package jmine.tec.report.impl.table.pdf;

import java.text.SimpleDateFormat;
import java.util.Date;

import jmine.tec.report.api.table.ReportCell;
import jmine.tec.report.impl.table.RendererParameterInterface;
import jmine.tec.report.impl.table.ReportTableBuilder;

import com.lowagie.text.Element;

/**
 * Implementação default de formatter de células de relatório
 * 
 * @author lundberg
 */
public class DateCellPDFRenderer extends AbstractCellPDFRenderer {

    private static final String DEFAULT_DATE_FORMAT = "dd/MM/yyyy";

    /**
     * {@inheritDoc}
     */
    public String getRendererType() {
        return ReportTableBuilder.TYPE_DATE;
    }

    /**
     * {@inheritDoc}
     */
    public String getFormattedString(ReportCell cell) {
        if (cell.getValue() == null) {
            return "";
        } else {
            String pattern = new RendererParameterInterface(cell).getDatePattern();
            pattern = (pattern != null && !"".equals(pattern)) ? pattern : DEFAULT_DATE_FORMAT;
            return new SimpleDateFormat(pattern).format(Date.class.cast(cell.getValue()));
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected int getHorizontalAlignment(RendererParameterInterface rpi) {
        return Element.ALIGN_CENTER;
    }
}
